package com.tensquare.user.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tensquare.user.pojo.TbPermission;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public interface PermissionDao extends BaseMapper<TbPermission> {

    @Select("select * from tb_permission where id in(" +
            "select permission_id from tb_role_per where role_id in (" +
            "select role_id from tb_user_role where user_id = #{userId}))")
    ArrayList<TbPermission> selectByUserId(@Param("userId")String userId);

    @Select("select * from tb_permission where id in(" +
            "select permission_id from tb_role_per where role_id in (" +
            "select role_id from tb_user_role where user_id = " +
            "select id from from tb_user where account = #{account}))")
    ArrayList<TbPermission> selectByUserAccount(@Param("account")String account);

    int updatePermissionByProp(Map<String,Object> map,Integer id);

    /**
     * 按条件删除tb_role_per表的数据
     * @param permissionIds permission_id的集合
     */
    int delRolePerByPermissionId(@Param("permissionIds") ArrayList<Integer> permissionIds);

    /**
     * 根据角色Id查询权限
     * @param roleId 角色Id
     */
    List<TbPermission> findByRoleId(@Param("roleId") Integer roleId);

}
